﻿using System;
using System.Data.Objects;
using System.Data.Services;
using System.Linq;
using System.Linq.Expressions;

namespace AstoriaPlus
{
	public interface IDataServiceRules<TDataService, TDataSource> : IFluentInterface
		where TDataService : DataService<TDataSource>
		where TDataSource : class
	{
		IDataServiceRules<TDataService, TDataSource, TEntity> For<TEntity>(Expression<Func<TDataSource, IObjectSet<TEntity>>> entitySetProperty)
			where TEntity : class;

		IDataServiceRules<TDataService, TDataSource, TEntity> For<TEntity>(Expression<Func<TDataSource, IQueryable<TEntity>>> entitySetProperty)
			where TEntity : class;

		void SetOperationRights(Expression<Action<TDataService>> operationMethod, ServiceOperationRights rights);

		IDataServiceRules<TDataService, TDataSource> OnChange(Action<IEntityChangeRules<TDataService, TDataSource>> changeRules);
	}

	public interface IDataServiceRules<TDataService, TDataSource, TEntity> : IFluentInterface
		where TDataService : DataService<TDataSource>
		where TDataSource : class
		where TEntity : class
	{
		ExtendedDataServiceConfiguration<TDataService, TDataSource> Configuration { get; }

		IDataServiceRules<TDataService, TDataSource, TEntity> SetRights(EntitySetRights rights);

		IDataServiceRules<TDataService, TDataSource, TEntity> OnChange(Action<IEntityChangeRules<TDataService, TDataSource, TEntity>> changeRules);

		IDataServiceRules<TDataService, TDataSource, TEntity> OnQuery(Func<IEntityQueryRules<TDataService, TDataSource, TEntity>, Expression<Func<TEntity, DataServiceQueryContext<TDataService, TDataSource>, bool>>> queryRules);
	}
}
